import { Controller, Get, Post, Body, Param } from '@nestjs/common';
import { MotionService } from './motion.service';
import { CurrentUserType } from 'src/types/user';
import { CurrentUser } from '../auth/current-user.decorator';

// dto
import CreateMotionDto from './dto/create.motion.dto';
import UpdateMotionDto from './dto/update.motion.dto';

@Controller('api')
export class MotionController {
  constructor(private readonly motionService: MotionService) {}
  @Get('getMotions')
  getMotions(@CurrentUser() user: CurrentUserType) {
    return this.motionService.getMotions(user.id);
  }

  @Get('getMotions/:motionId')
  getMotion(@Param('motionId') id: string) {
    return this.motionService.getMotion(id);
  }

  @Post('addMotion')
  async addMotion(
    @CurrentUser() user: CurrentUserType,
    @Body() data: CreateMotionDto,
  ) {
    return this.motionService.createMotion(user.id, data);
  }

  @Post('deleteMotion')
  deleteMotion(@Body('motionId') id: string) {
    return this.motionService.deleteMotion(id);
  }

  @Post('deleteMotionAndRecord')
  deleteMotionAndRecord(
    @CurrentUser() user: CurrentUserType,
    @Body('motionId') motionId: string,
  ) {
    return this.motionService.deleteMotionAndRecords(user.id, motionId);
  }

  @Post('updateMotion')
  updateMotion(@Body() data: UpdateMotionDto) {
    return this.motionService.updateMotion(data._id, data);
  }
}
